package com.lfk.demo.Ability;

import com.lfk.demo.ResourceTable;
import ohos.aafwk.ability.Ability;

import com.lfk.justwetools.Component.ReadView.ReadView;
import ohos.aafwk.content.Intent;
import ohos.agp.components.ComponentContainer;
import ohos.agp.components.StackLayout;
import ohos.utils.net.Uri;

import java.io.File;


public class ReadAbility extends Ability {
    private ReadView readView;
    @Override
    protected void onStart(Intent intent) {
        super.onStart(intent);
        setPattern(ResourceTable.Pattern_base);
        File dir = null;
        Uri fileUri = getIntent().getUri();
        if (fileUri != null) {
            dir = new File(fileUri.getDecodedPath());
        }
        readView = null;
        if (dir != null) {
            readView = new ReadView(this,dir.getPath());
            readView.setId(0xffff001);
        }
        else
            terminateAbility();

        StackLayout layout = new StackLayout(this);
        layout.setLayoutConfig(new ComponentContainer.LayoutConfig(
                ComponentContainer.LayoutConfig.MATCH_PARENT, ComponentContainer.LayoutConfig.MATCH_PARENT));
        layout.addComponent(readView, new StackLayout.LayoutConfig(
                StackLayout.LayoutConfig.MATCH_PARENT, StackLayout.LayoutConfig.MATCH_PARENT));
        setUIContent(layout);
    }

    @Override
    protected void onBackground() {
        super.onBackground();
        readView.setOnPause();
    }
}
